package com.yazi.mxz.common.db.dao.impl;



import java.util.HashMap;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.yazi.mxz.common.db.dao.CategoryDao;
import com.yazi.mxz.common.entity.beans.Category;

import com.myframework.smhj.hibernate.dao.BasicDao;

@Repository("categoryDao")
public class CategoryDaoImpl extends BasicDao<Category> implements CategoryDao {

	
	public CategoryDaoImpl() {
		super(Category.class);
		
	}

	@Override
	public Criteria getExample(Category cat, String searchWord) {
		Criteria c = super.getExample(cat, searchWord);
		
		// 关联对象条件
		if (null != cat) {
			// 父类
			Category parentCat = cat.getCategory();
			if (null != parentCat) {
				// 父类ID
				if (null != parentCat.getCatId()) {
					c.add(Restrictions.eq("category.catId", parentCat.getCatId()));
				} else {
					// ...父类其它条件
				}
			}
			// ...其它关联对象条件
		}
		
		// ...关键字searchWord条件
		
		return c;
	}

	@Override
	public int delete(long catId) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("cat_id", catId);
		return executeUpdate("delByCatIdSql", param);
	}
	
}
